/*
 * @Author: szx
 * @Date: 2022-03-03 13:34:09
 * @LastEditTime: 2022-03-03 13:50:48
 * @Description:
 * @FilePath: \leetcode\2100-2199\2140\2140.js
 */
/**
 * @param {number[][]} questions
 * @return {number}
 */
var mostPoints = function (questions) {
    // dp为当前获得最多的分数
    const n = questions.length;
    const dp = new Array(n + 1).fill(0);
    for (let i = n - 1; i >= 0; i--) {
        if (i + questions[i][1] < n) {
            dp[i] = Math.max(dp[i + 1], dp[i + questions[i][1] + 1] + questions[i][0]);
        } else {
            dp[i] = Math.max(dp[i + 1], questions[i][0]);
        }
    }
    return dp[0];
};

console.log(
    mostPoints([
        [3, 2],
        [4, 3],
        [4, 4],
        [2, 5]
    ])
);
